define(['app'],function(app){return {module: function($scope, $http, eventBusService, httpService, params) {
	$scope.form.academic = params.academic;
	$scope.form.semester = params.semester;
	$scope.form.fk_unit = params.fk_unit;
	$scope.form.fk_user = params.fk_user;
	$scope.form.week = params.week;
	$scope.form.time = params.time;
	$scope.form.weekunit = params.weekunit;
	
	var init =function(){
		//查询当前学年学期
		httpService.post(app.urls.prop_select,{"prop_group":'SCORE','status':'0'},function(data){
			if("0000" === data.code){
				for(var i=0;i<data.data.length;i++){
					if(data.data[i].prop_key=='STU_YEAR'){
						$scope.form.academic =  data.data[i].prop_pk;
					}
					if(data.data[i].prop_key=='STU_TERM'){
						$scope.form.semester =  data.data[i].prop_pk;
					}
				}

			}else{
				alert(data.msg);
			}
		});
	}
	if($scope.form.academic=='undefined'||$scope.form.academic==undefined||$scope.form.academic==''||$scope.form.academic==null){
		init();
	}
	//查询个人信息
	httpService.post(app.urls.getUserInfo,{},function(data){
		if("0000" === data.code){
			$scope.form.fk_user =  data.data.id;
			$scope.form.name =  data.data.displayName;
			//查询主校区和分校区
			httpService.post(app.urls.unit_selectSchoolAndAttach,{"fk_unit":data.data.unitId},function(data){
				if("0000" === data.code){
					$scope.unitList = data.data;
					if($scope.unitList.length =='1'){$scope.form.fk_unit =  $scope.form.gzdwpk;}
				}else{
					alert(data.msg);
				}
			});
		}else{
			alert(data.msg);
		}
	});
	//查询学年
	httpService.post(app.urls.prop_select,{"prop_group":'SCORE',"prop_key":'STU_YEAR'},function(data){
		if("0000" === data.code){
			$scope.academics =  data.data;
		}else{
			alert(data.msg);
		}
	});
	//查询学期
	httpService.post(app.urls.prop_select,{"prop_group":'SCORE',"prop_key":'STU_TERM'},function(data){
		if("0000" === data.code){
			$scope.semesters = data.data;
		}else{
			alert(data.msg);
		}
	});
	//查询年级
	$scope.find = function (){
		$scope.form.time = false;
		httpService.post(app.urls.course_time_selectIfExit,$scope.form,function(data){
			if(data.data>0){
				$scope.form.time = true;
			}else{
				alert(data.msg);
			}
		});
		for(var i=0;i<$scope.unitList.length;i++){
			if($scope.unitList[i].id == $scope.form.fk_unit){
				$scope.form.weekunit = $scope.unitList[i].week;
			}
		}
		if($scope.form.weekunit == '0'){
			$scope.form.week = '0';
		}
		if($scope.form.weekunit == '1'){
			$scope.form.week = '';
		}
	}
	
	$scope.saveForm = function(){
		if($scope.form.fk_unit=='undefined'||$scope.form.fk_unit==undefined||$scope.form.fk_unit==''||$scope.form.fk_unit==null){
			alert("请选择校区");
			return;
		}
		if($scope.form.weekunit == undefined){
			alert("请设置该学校的课表类型");
			return;
		}
		if($scope.form.weekunit == '1' && ($scope.form.week=='undefined'||$scope.form.week==undefined||$scope.form.week==''||$scope.form.week==null)){
			alert("请选择单/双周");
			return;
		}
		if(!$scope.form.time){
			alert("请设置上课时间");
			return;
		}
		var menu = {};
		menu.url = "modules/mobile/school/course/table/list?academic="+$scope.form.academic+"&semester="+$scope.form.semester+"&fk_unit="+$scope.form.fk_unit+"&fk_user="+$scope.form.fk_user+"&week="+$scope.form.week+"&time="+$scope.form.time+"&weekunit="+$scope.form.weekunit;
		eventBusService.publish("modules.mobile.load",menu);
	}
	
	//返回
	$scope.goback = function(){
		window.history.back();
	}
}}});